var Window = {
  addListeners: function()
  {
    window.addEventListener("load", Window.startup, false);
    window.addEventListener("unload", Window.shutdown, false);
  },
  
  removeListeners: function()
  {
    window.removeEventListener("load", Window.startup, false);
    window.removeEventListener("unload", Window.shutdown, false);
  },
  
  startup: function()
  {
    if (server != null) server.start();

    Browser.addListeners();
    ContextMenu.addListeners();
    
    if (!popup) {
      $('main-browser').loadURI("chrome://lark/content/loading.html", null, null);
      setTimeout(Window.loadURI, 1000);
    }
  },
  
  shutdown: function()
  {
    if (server != null) server.stop();

    Browser.removeListeners();
    ContextMenu.removeListeners();
    Window.removeListeners();
  },
  
  loadURI: function()
  {
    $('main-browser').loadURI("http://localhost:" + server.port, null, null);
  }
}